﻿using PoliticalClassifier.Support;
using System.Collections.Generic;

namespace PoliticalClassifier.DataSource
{
    /// <summary>
    /// DataSourceLoadResults provides a container and API for checking 
    /// the results of loading a data file.
    /// </summary>
    internal class DataSourceLoadResults : IDataSourceLoadResults
    {
        #region Construction
        /// <summary>
        /// Constructs an empty result set.
        /// </summary>
        public DataSourceLoadResults()
        {
            Warnings = new List<IDataSourceLoadWarning>();
            Errors = new List<IDataSourceLoadError>();
        }
        #endregion

        #region Public Properties
        /// <summary>
        /// Gets whether or not the data is in good enough shape to process.
        /// </summary>
        public bool CanContinue
        {
            get { return ErrorCount == 0; }
        }

        /// <summary>
        /// Gets the number of errors in the data file.
        /// </summary>
        public int ErrorCount
        {
            get { return Errors.Count; }
        }

        /// <summary>
        /// Gets the number of warnings in the data file.
        /// </summary>
        public int WarningCount
        {
            get { return Warnings.Count; }
        }
        #endregion

        #region Public Methods
        /// <summary>
        /// Gets an enumeration of the errors in the data file.
        /// </summary>
        /// <returns>The errors.</returns>
        public IEnumerable<IDataSourceLoadError> GetErrors()
        {
            return Errors;
        }

        /// <summary>
        /// Gets an enumeration of the warnings in the data file.
        /// </summary>
        /// <returns>The warnings.</returns>
        public IEnumerable<IDataSourceLoadWarning> GetWarnings()
        {
            return Warnings;
        }

        /// <summary>
        /// Added a warning to the results.
        /// </summary>
        /// <param name="warning">A warning.</param>
        public void AddWarning(IDataSourceLoadWarning warning)
        {
            Warnings.Add(warning);
        }

        /// <summary>
        /// Adds an error to the results.
        /// </summary>
        /// <param name="error">An error.</param>
        public void AddError(IDataSourceLoadError error)
        {
            Errors.Add(error);
        }
        #endregion

        #region Private Properties
        private List<IDataSourceLoadWarning> Warnings { get; set; }
        private List<IDataSourceLoadError> Errors { get; set; }        
        #endregion
    }
}
